package io.renren.softpark.util;

import io.renren.softpark.dao.SortDao;
import io.renren.softpark.dto.ColumnDto;
import io.renren.softpark.dto.SortDto;
import io.renren.softpark.dto.TwoMenuDto;
import io.renren.softpark.entity.ColumnEntity;
import io.renren.softpark.entity.PlatesEntity;
import io.renren.softpark.entity.SortEntity;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * @author HaiPeng Wang
 * @date 2020/8/27 10:54
 * @Description:
 */
@Data
public class MenuUtil {

    public static List<TwoMenuDto> getTwoLevelMenu(List<SortEntity> sortList, List<PlatesEntity> platesList){
        List<TwoMenuDto> twoMenuDtoList = new ArrayList<>();
        for (PlatesEntity platesEntity : platesList){
            Integer id = platesEntity.getPlateId();
            List<SortDto> sortDtoList = new ArrayList<>();
            for (SortEntity sortEntity : sortList){
                if (sortEntity.getParentId().equals(id)){
                    SortDto sortDto = new SortDto();
                    sortDto.setSortId(sortEntity.getSortId());
                    sortDto.setSortName(sortEntity.getSortName());
                    sortDtoList.add(sortDto);
                }
            }
            TwoMenuDto twoMenuDto = new TwoMenuDto();
            twoMenuDto.setSortId(0);
            twoMenuDto.setSortName(platesEntity.getPlateName());
            twoMenuDto.setSortList(sortDtoList);
            twoMenuDtoList.add(twoMenuDto);
        }
        return twoMenuDtoList;
    }

    public static List<TwoMenuDto> getThreeLevelMenu(List<PlatesEntity> platesList,List<SortEntity> sortList , List<ColumnEntity> columnList){
        List<TwoMenuDto> twoMenuDtoList = new ArrayList<>();
        for (PlatesEntity platesEntity : platesList){
            Integer id = platesEntity.getPlateId();
            List<SortDto> sortDtoList = new ArrayList<>();
            for (SortEntity sortEntity : sortList){
                if (sortEntity.getParentId().equals(id)){
                    SortDto sortDto = new SortDto();
                    sortDto.setSortId(1);
                    sortDto.setSortName(sortEntity.getSortName());
                    List<ColumnDto> columnDtoList = new ArrayList<>();
                    for (ColumnEntity columnEntity : columnList){
                        if (columnEntity.getParentId().equals(sortEntity.getSortId())){
                            ColumnDto columnDto = new ColumnDto();
                            columnDto.setSortId(columnEntity.getColumnId());
                            columnDto.setSortName(columnEntity.getColumnName());
                            columnDtoList.add(columnDto);
                        }
                    }
                    sortDto.setSortList(columnDtoList);
                    sortDtoList.add(sortDto);
                }
            }
            TwoMenuDto twoMenuDto = new TwoMenuDto();
            twoMenuDto.setSortId(0);
            twoMenuDto.setSortName(platesEntity.getPlateName());
            twoMenuDto.setSortList(sortDtoList);
            twoMenuDtoList.add(twoMenuDto);
        }
        return twoMenuDtoList;
    }


}
